<?php
/**
 * URL调度类
 * 
 * @file Router.class.php
 * @create 2012-08-03
 * @version v1.0
 * @author veapon 
 * @copyright (C) veapon.com
 */
if( !defined('__ROOT__') ) die('Access Denied');
class Router{

	/**
	 * 解释URL
	 * 
	 * @return 
	 * @since v1.0
	 * @create 2012-08-03
	 */
	public static function init(){
		$queryString = "";
		$url = array();
		if( false!== strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) ){
			$queryString = str_replace($_SERVER['SCRIPT_NAME'],"",$_SERVER['REQUEST_URI']);
			$queryString = substr($queryString,1);
		}

		$url = explode('/', trim($queryString, '/'));
		$module = ($url[0]) ? strtolower($url[0]) : 'index';
		$controller = isset($url[1]) ? strtolower($url[1]) : 'index';
		$action = isset($url[2]) ? strtolower($url[2]) : 'index';
		define('MODULE', $module);
		define('CONTROLLER', $controller);
		define('ACTION', $action);
		if( isset($url[3]) ){
			for($i=3; $i<count($url); $i=$i+2){
				$_GET[$url[$i]] = $url[$i+1];
			}
		}
		return;
	}
}
